package com.dqhl.community.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.dqhl.community.R;
import com.dqhl.community.base.BaseMyAdapter;
import com.dqhl.community.model.Goods;
import com.dqhl.community.util.Config;

import org.xutils.x;

import java.util.List;

/**
 * Created by Administrator on 2016/9/20.
 */
public class YingYangPinAdapter extends BaseMyAdapter {

    private LayoutInflater inflater;

    private List<Goods> list;
    private onBuyClickListener onBuyClickListener;

    public void setOnBuyClickListener(YingYangPinAdapter.onBuyClickListener onBuyClickListener) {
        this.onBuyClickListener = onBuyClickListener;
    }
    public YingYangPinAdapter(Context context,List<Goods> list) {
        super(context);
        this.list=list;
        inflater= (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {

        View v = inflater.inflate(R.layout.gv_yingyangpin_item, viewGroup, false);

        ImageView mIv= (ImageView) v.findViewById(R.id.iv_img);
        TextView mTvTitle= (TextView) v.findViewById(R.id.tv_title);
        TextView mTvPrices= (TextView) v.findViewById(R.id.tv_prices);
        TextView mTvBay= (TextView) v.findViewById(R.id.tv_yingyang_bay);

        final Goods goods = list.get(i);
        x.image().bind(mIv, Config.Api.base_img_url + goods.getPic_a());
        mTvTitle.setText(goods.getName());
        mTvPrices.setText("¥"+goods.getPrice());
        mTvBay.setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        onBuyClickListener.doBuy(goods.getId(), goods.getPic_a(), goods.getName(), goods.getPrice());
                    }
                }
        );
        return v;
    }
    public interface onBuyClickListener {
        void doBuy(String goodsId, String strImg, String strName, String strPrice); //购买
    }
}
